package cn.edu.xust.configuration.exception;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author ufo
 * @Description 错误枚举 code msg
 * @Date 2021/7/30 18:17
 * @Version 1.0
 */
@Slf4j
public enum ErrorConstant {


    // -1为通用失败（根据ApiResult.java中的构造方法注释而来）
    FAIL(-1, "common fail"),
    // 0为成功
    SUCCESS(0, "success"),

    error_pic_file(3, "非法图片文件"),
    error_pic_upload(4, "图片上传失败"),
    error_record_not_found(5, "没有找到对应的数据"),
    error_max_page_size(6, "请求记录数超出每次请求最大允许值"),
    error_create_failed(7, "新增失败"),
    error_update_failed(8, "修改失败"),
    error_delete_failed(9, "删除失败"),
    error_search_failed(10, "查询失败"),
    error_count_failed(11, "查询数据总数失败"),
    error_string_to_obj(12, "字符串转java对象失败"),
    error_invalid_argument(13, "参数不合法"),
    error_update_not_allowed(14, "更新失败:%s"),
    error_duplicated_data(15, "数据已存在"),
    error_unknown_database_operation(16, "未知数据库操作失败，请联系管理员解决"),
    error_column_unique(17, "字段s%违反唯一约束性条件"),
    error_file_download(18, "文件下载失败"),
    error_file_upload(19, "文件上传失败"),


    //600
    not_found(600, "未找到相关数据"), gateway_not_online(601,"网关未连接" ),
    vertify_err(602,"校验失败" ), num_err(603,"设备数量异常" ), gateway_not_exsit(604,"网关不存在" ), hotel_not_found(605,"酒店不存在" ),
    date_need(606,"需要日期参数" ),content_null(607,"准备发送的内容为空" ),

    //1000
    //1000以内是系统错误，
    no_login(1000, "没有登录"),
    config_error(1001, "参数配置表错误"),
    user_exist(1002, "用户已存在"),
    userpwd_not_exist(1003, "用户名不存在或者密码错误"),
    common_reply(1004, "暂不支持该操作,请联系管理员"),
    mac_not_found(1005, "设备信息不存在"),
    room_not_found(1007, "房间信息不存在"),
    device_not_init(1008, "设备未初始化呢"),
    user_not_exist(1009, "用户不存在"),
    api_menu_null(1010, "当前菜单列表为空"),
    data_not_compelete(1011, "数据不完整"),
    device_not_exist_in_this_room(1012, "此房间无AI设备"),
    date_parse_error(1013, "日期格式错误"),
    xbl_room_not_checkin(1014, "上次登录已失效，请重新尝试"),
    xbl_phone_not_checkin(1015, "该手机号未查询到入住记录 "),
    device_mac_not_find(1016, "设备mac不存在"),
    Parameters_calibration_failure(1017, "参数校验失败"),
    date_timeout(1018, "日期超时"),
    itemhotel_already_exist(1019, "物品已存在"),
    itemhotel_not_exist(1020, "物品不存在"),
    itemtype_already_exist(1021, "物品类型已存在"),
    itemtype_not_exist(1022, "物品类型不存在"),
    item_already_exist(1023, "物品已存在"),
    item_not_exist(1024, "物品不存在"),
    hotelitem_not_exist(1025, "酒店物品不存在"),
    hotelitem_already_exist(1026, "酒店物品已存在"),
    tcl_badterminal(1020, "电视连接失败，请稍后重试吧"),
    tcl_localbad(1021, "抱歉，我遇到错误啦，请您别生气，联系下管理员吧"),
    tcl_tv_not_found(1022, "暂未发现与之关联的电视，请稍后再试吧"),
    tcl_order_not_found(1023, "该指令我还不会，抱歉啦"),
    tcl_order_(1024, "该指令我还不会，抱歉啦"),
    gzh_regis_not_same(1031, "您在小程序选择的酒店不一致"),
    gzh_regis_not_find(1032, "你还未在小程序注册过"),
    yg_lock_not_found(1040, "门锁信息未查到"),
    frg_lock_not_found(1041, "门锁信息未查到"),
    itemtype_not_found(1050, "物品类型未找到"),
    ota_mac_not_found(1060, "有不存在的设备，升级取消"),
    minip_user_phone_over_than_one(1070, "该手机号已使用，请联系酒店前台咨询"),
    minip_expire_checkout(10701, "日期有效期已过,请联系酒店前台咨询"),
    post_sresponse_err(1080, "接口调用出错"),
    staff_register_mul(1090, "职工已经注册过了"),
    staff_register_over(1091, "职工信息异常-过多"),
    staff_register_err(1092, "该微信用户异常注册"),
    staff_num_too_much(1093, "员工注册异常"),
    staff_not_found(1094, "职工不存在"),
    staff_num_err(1094, "职工数量异常"),
    sms_interval_too_short(1095, "验证码发送频繁，请稍后重试"),
    staff_phone_register_mul(1096, "职工注册手机号已存在"),
    odd_not_found(1100, "工单不存在"),
    odd_deal_not_self(1101, "不允许处理不属于自己的单"),
    item_not_found_in_hotel(1300, "酒店内未有该物品"),
    item_mul(1301, "酒店商品异常"),
    hotel_num_err(1401, "酒店数量异常"),
    xl_hotel_not_found(1501, "未找到该酒店"),
    signfail(1502, "认证错误，请勿非法尝试"),
    ladder_not_found(1503, "梯控未安装"),
    hotel_tv_not_config(1504, "酒店电视未开通云服务"),
    mulsubmmit(1505, "请勿重复提交"),
    order_backed(1506, "订单已退款，请勿重复操作"),
    order_not_found(15067, "订单不存在"),
    order_blocked(15068, "订单锁定中"),
    order_cannot_cancel(15068,"订单不支持取消"),
    order_quit(15069, "订单已退款，无法接单"),
    order_state_error(15070, "订单状态异常"),
    not_support_del(15071, "现在已不支持取消"),
    post_food_error(15072, "推送出错，请重试"),
    xop_post_order_fail(15073, "xop下单失败"),
    not_support(15074, "对不起，我还未开通此功能，请联系前台或换种说法吧。"),
    mobile_is_null(15075, "没有预留手机号"),
    edit_fail(15076, "修改失败"),
    control_order_not_found(15077,"抱歉，我还不会这项指令" ),
    not_have_checkinfo(15078,"当前房间无住客信息，无法点单" ),
    cancel_food_order_fail(15079, "西软点餐撤销结账失败"),
    hotel_not_union_xop(15080,"该酒店未关联西软点餐系统" ),
    remove_fail(15081,"删除失败" ),
    save_fail(15082,"保存失败" ),
    password_error(15083,"密码错误" ),
    pa_short(15084,"密码长度不正确" ),
    question_not_found(15085,"抱歉，这个问题酒店也没告诉我，您咨询下前台哦" ),
    room_device_num_max(15086,"房间设备数量超过限制" ),room_device_num_zero(15087,"房间无设备" ),
    checkout_xop_fail(15088,"西软餐单结账失败" ),
    service_not_found(15089,"不存在该服务" ),
    cancel_food_order_disable(15090,"当前餐单不可取消" ),
    hotel_mixinfo_not_perfect(15091,"酒店信息配置不全" ),
    repair_duplicate(15092,"维修物品已存在" ),
    welcome_duplicate(15093,"礼宾服务已存在" ), data_too_long(15094,"数据记录太大" ),
    num_error(15095,"数量异常" ), data_not_valid(15096,"数据有误" ),
    food_price_not_found(15097,"菜品价格不能为空" ),
    state_invalid(15098,"状态已失效" ), num_zero(15099,"数量为0" ),
    mul_oddid(15100,"单号重复,请重新进入。" ), room_floor_num_not_match(15101,"房间楼层数量不一致" ),
    hotel_already_exist(15102,"酒店号已存在" ), odd_list_null(15103,"客房工单列表为空" ),
    time_not_in_match(15104,"当前时间不在规定范围中" ), SIGN_NOT_RIGHT(15103,"sign验证不正确" ),
    user_can_not_find_moid(15104,"当前角色无权接收会议工单" ), mul_data_exist(15105,"存在重复数据" ),
    hotel_config_acid_not_found(15106,"该酒店的ACID配置为空" ),
    hotel_config_acconfig_not_found(15107,"该酒店的ACCONFIG配置为空" ),
    role_exist(15108,"角色id重复" ),role_name_exist(15109,"角色名称已被使用" ),
    role_have_been_use(15110,"角色当前有用户在使用" ), role_not_exist(15111,"角色不存在" ),
    user_vertify_fail(15112,"用户名验证失败" ),
    act_have_no_prev_search_the_act(15113,"您没有权限查询此账户信息，请勿非法访问！" ),
    illegal_access(15114,"非法访问" ),
    act_already_create_roles(15115,"当前账号下，已创建了子角色" ),
    role_have_shareroles(15116,"当前角色有共享角色" ),
    mobile_get_fail(15117,"手机号获取失败" ), user_can_not_edit(15118,"该用户没有账号，无法修改账号信息" ),
    role_is_empty(15119,"该账号无角色" ),
    valid_code_err(15120,"验证码不正确" ), no_listen_content(15121,"抱歉，刚刚什么也没听到，请您再说一次" ),
    yg_lock_roomid_not_found(15122,"该房号的门锁信息不存在"),
    pub_area_null(15123,"该酒店没有公区门锁配置" ),
    yg_lock_pub_area_have_exist(15124,"该房间号已配置为公区门锁" ),

    not_config_monthsalary(15125,"未配置月工资"),
    zero_monthsalary(15126,"月工资配置为0" ),
    lierda_not_found_scene(15127,"lierda找不到情景模式" ),
    xophotel_not_config_dailysale(15128,"该酒店没有配置西软营业信息" ),
    fta_login_err(16000,"登录错误，请联系管理员" ),
    fta_user_not_found(16001,"账号密码错误或用户不存在" ),
    fta_openid_get_err(16002,"获取微信id失败" ),
    fta_data_null(16003,"日期范围数据为空" ), act_not_access(106004,"账号不在白名单内" ),
    item_more_than_fifteen(106005,"查询范围不可超过15项" ),
    item_more_than_thirty(106006,"查询范围不可超过30项" ),
    act_not_allow_empty(106007,"账号记录为空" ),
    act_already_login_other_device(106008,"该房间已在其他微信上登录，详情请咨询工作人员" ),
    roomid_not_match(106009, "房间号不匹配"),
    mini_not_have(106010,"该房间当前未有用户登录小布鲁" ),
    xl_face_timeout(106011,"电视接口访问超时，请联系管理员" ),
    result_null(106012,"查询结果为空" ),
    jj_resp_control_err(106013,"电视控制失败啦，可通知管理员检查" ), time_already_exist(106014,"时间已存在" ),

    alreadyhave(106015,"已存在" ), not_found_info(106016,"没有相关信息" ),
    lierda_not_init_dateway(106017,"该酒店房间没有初始化利尔达的网关设备" ),
    never_send_speech(106018,"您别发了，驰驰" ), hoteljob_not_found(106019,"该酒店岗位模板未设置" ),
    tcl_token_get_err(106020, "tcltoken获取失败"), tv_order_not_config(106021,"抱歉，该电视指令我还不会" ),
    need_input_pwd(106022,"本次需要输入密码" ), fta_no_union_remove(106023,"没有可解除的绑定" ), zero_pid(106024,"该账号权限数量为空" )
    , sel_timeout(106024,"网关无回复，查询超时" ), room_have_device(106025,"该房间已经有该类型设备，请使用替换功能" ), macid_alreadyhave(106026,"该mac已存在" ),
    gen_err(106027,"生成指令失败，请检查日志" ),no_ip(106028,"通道中没有找到该ip"), timeout3(106029,"已超过3秒无响应，该设备可能不存在或请慢速查询" ),
    client_closed(106030,"客户端已关闭" ), internal_err(106031,"终端异常(大概率不会显示这个)" ), resp_low_8(106032,"响应长度小于8，解析失败" ),
    gen_cmd_null(106033,"生成指令为空，请慢速重试" ), ele_power_parse_null(106034,"电量解析为空，请重试" ), wt_data_parse_err(106035,"水表解析失败，数据有误" ), other_query(106036,"有其他查询正在执行，请稍后再试" )
    , gateway_zero(106037,"网关数量为0" ), date_so_early(106038,"日期不得早于2024-04" )
    , date_so_late(106039,"日期范围太未来" );

    private int code;
    private String msg;

    ErrorConstant(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define) {
        try {
            return ErrorConstant.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return FAIL.getErrorCode();
        }
    }

    public static String getMsg(String define) {
        try {
            return ErrorConstant.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return FAIL.getErrorMsg();
        }
    }

    public static String getMsg(int code) {
        for (ErrorConstant err : ErrorConstant.values()) {
            if (err.code == code) {
                return err.msg;
            }
        }
        return "errorCode not defined ";
    }

    public int getErrorCode() {
        return code;
    }

    public String getErrorMsg() {
        return msg;
    }


}
